import { _decorator, Color, Component, Sprite } from 'cc'
const { ccclass, property } = _decorator

/**背包格子 */

@ccclass('BagGrilditem')
export class BagGrilditem extends Component {
  /** 状态：0，可放置，1，不可放置 */
  public m_state = 0
  /**放置的物品类型 */
  public m_type = -1
  private col = 0

  private row = 0
  protected ItemName: string = ''
  set gridObj(value: { col: number, row: number }) {
    this.col = value.col
    this.row = value.row
  }
  get gridObj() {
    return { col: this.col, row: this.row }
  }
  private items: BagGrilditem[] = []
  private grid: Map<string, BagGrilditem> = new Map()
  public create(col: number, row: number, name: string) {
    this.gridObj = { col: col, row: row }
    this.m_state = 0
    this.node.name = name
    this.node.getChildByName('Node').active = false
  }

  getItemPosition() {
    return { x: this.node.getPosition().x, y: this.node.getPosition().y }
  }

  setDeafult() {
    this.node.getComponent(Sprite).color = new Color().fromHEX('FFFFFF');
  }

  setGreen() {
    this.node.getComponent(Sprite).color = new Color().fromHEX('7ed263');
  }

  setRed() {
    this.node.getComponent(Sprite).color = new Color().fromHEX('dd6662');
  }

  setYellow() {
    this.node.getComponent(Sprite).color = new Color().fromHEX('dbc464');
  }
  // 添加物品到指定格子
  addItemToGrid(type: number) {
    this.m_type = type
  }

  // 获取指定格子的物品
  getItemFromGrid(): Number {
    return this.m_type
  }
  start() { }

  update(deltaTime: number) { }
}
